package com.sqfw.project.knowledge.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sqfw.project.knowledge.domain.KnowledgeSort;
import com.sqfw.project.knowledge.service.IKnowledgeSortService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.web.page.TableDataInfo;

/**
 * 知识分类Controller
 * 
 * @author ruoyi
 * @date 2023-06-19
 */
@RestController
@RequestMapping("/knowledgeSort")
public class KnowledgeSortController extends BaseController
{
    @Autowired
    private IKnowledgeSortService knowledgeSortService;

    /**
     * 查询知识分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:sort:list')")
    @GetMapping("/list")
    public TableDataInfo list(KnowledgeSort knowledgeSort)
    {
        startPage();
        List<KnowledgeSort> list = knowledgeSortService.selectKnowledgeSortList(knowledgeSort);
        return getDataTable(list);
    }

    /**
     * 导出知识分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:sort:export')")
    @Log(title = "知识分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowledgeSort knowledgeSort)
    {
        List<KnowledgeSort> list = knowledgeSortService.selectKnowledgeSortList(knowledgeSort);
        ExcelUtil<KnowledgeSort> util = new ExcelUtil<KnowledgeSort>(KnowledgeSort.class);
        util.exportExcel(response, list, "知识分类数据");
    }

    /**
     * 获取知识分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sort:query')")
    @GetMapping(value = "/{autoid}")
    public AjaxResult getInfo(@PathVariable("autoid") String autoid)
    {
        return success(knowledgeSortService.selectKnowledgeSortByAutoid(autoid));
    }

    /**
     * 新增知识分类
     */
//    @PreAuthorize("@ss.hasPermi('system:sort:add')")
    @Log(title = "添加知识分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody KnowledgeSort knowledgeSort)
    {
        return toAjax(knowledgeSortService.insertKnowledgeSort(knowledgeSort));
    }

    /**
     * 修改知识分类
     */
//    @PreAuthorize("@ss.hasPermi('system:sort:edit')")
    @Log(title = "修改知识分类", businessType = BusinessType.DELETE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody KnowledgeSort knowledgeSort)
    {
        return toAjax(knowledgeSortService.updateKnowledgeSort(knowledgeSort));
    }

    /**
     * 删除知识分类
     * */
    @PreAuthorize("@ss.hasPermi('system:sort:delete')")
    @Log(title = "删除知识分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("autoid") String autoid) {
        return toAjax(knowledgeSortService.deleteKnowledgeSortByAutoid(autoid));
    }


    /**
     * 删除知识分类
     */
    @PreAuthorize("@ss.hasPermi('system:sort:remove')")
    @Log(title = "知识分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{autoids}")
    public AjaxResult remove(@PathVariable String[] autoids)
    {
        return toAjax(knowledgeSortService.deleteKnowledgeSortByAutoids(autoids));
    }
}
